require 'typedef'
require 'math'
require 'table'




os.execute("mkdir dbh")
file_tag = ""
file_tags = {"Player", "Role", "Item", "Form", "Progress", "CoolDown"}
messages_all = {}

local do_generate = function(tag)
	file_tag = tag
	local protocolfile = "../db_"..tag..".lua"
	bind("template/template_db_handler.h", protocolfile, "dbh/DBMessageHandler"..tag..".h")
	bind("template/template_db_handler.cpp", protocolfile, "dbh/DBMessageHandler"..tag..".cpp")

	for _, v in ipairs(messages) do
		table.insert(messages_all, v)
	end
end

use_cpp_types()


for _, tag in ipairs(file_tags) do
	do_generate(tag)
end


bind("template/template_db_handler_mapper.h", "", "dbh/DBMessageHandlerMapper.h")
bind("template/template_db_handler_mapper.cpp", "", "dbh/DBMessageHandlerMapper.cpp")

os.execute("xcopy dbh\\*.* ..\\..\\TGame\\TServerMS\\Database /R /Y")

os.execute("rmdir /S /Q dbh")
